<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>创建实例</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
     <link rel="stylesheet" href="/static/css/style.css">
    <script src="/static/lib/layui/layui.js"></script>
</head>
<body>
       <table class="layui-hide" id="test" lay-filter="test" ></table>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" style="float: right">
                  <button class="layui-btn layui-btn-normal  layui-btn-sm data-add-btn" lay-event="getCheck_favor"> <i class="layui-icon" >&#xe654;</i></button>
                 <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete_Check"><i class="layui-icon">&#xe640;</i>删除flavor</button>
            </div>
        </script>
        <script type="text/html" id="barDemo">
          <a class="layui-btn layui-btn-sm  layui-btn-normal" lay-event="more">编辑flavor<i class="layui-icon layui-icon-down"></i></a>
        </script>
<script>
    var $ ,layer,table,dropdown;
    layui.use(['table','form','dropdown'], function(){
        table=layui.table;
        var form = layui.form;
         $=layui.jquery;
        layer=layui.layer;
        var dropdown = layui.dropdown;
        table.render({
            elem: '#test'
            ,url:'http://127.0.0.1:8000/zgh0381/flavors_listjson/'
            ,toolbar: '#toolbarDemo'
            ,title: '项目列表'
            ,totalRow: true
            ,cols: [
                [{type: 'checkbox', fixed: 'left'}
                 ,{field:'name', title:'flavor名称', width:100, fixed: 'left'}
                 ,{field:'vcpus', title:'VCPU数量', width:100, align:'center'}
                  ,{field:'ram', title:'内存', width:100, align:'center'}
                  ,{field:'disk', title:'根磁盘', width:100, align:'center'}
                  ,{field:'OS-FLV-EXT-DATA:ephemeral', title:'临时磁盘', width:100, align:'center'}
                  ,{field:'swap', title:'交换磁盘', width:100, align:'center'}
                  ,{field:'rxtx_factor', title:'RX/TX因子', width:100, align:'center'}
                  ,{field:'id', title:'标识', width:100, align:'center'}
                  ,{field:'os-flavor-access:is_public', title:'公有', width:100, align:'center'}
                  ,{field:'extra_specs', title:'元数据', width:100, align:'center'}

            ]
            ]
            ,page: true
            ,limit:10
            ,limits:[10,11,12,13]
            ,id:'orderTable'
        });


        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheck_favor':
                    layer.msg('已选中');
                    var data = checkStatus.data;
                    var flavor_info = JSON.stringify(data);
                      //向服务端发送删除指令
                         $.ajax({
                                            url:"/zgh0381/select_flavor/",
                                            type:"post",
                                            data:{"flavor_info":flavor_info},
                                            dataType: "json",
                                            async: true,  // 异步的ajax
                                             beforeSend: function (xhr, settings) {
                                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                                          },
                                            success:function(result) {
                                                    if(result.res == 1){

                                                       // 刷新
                                                       // location.reload();

                                                    }


                                            }
                   });
                    break;
                case 'add':
                   parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'创建项目'
                        ,content:'/zgh0381/projectcreate/'
                        ,area:['1000px','600px']
                        ,btn:'关闭'
                        ,btnAlign:'c'
                        ,yes:function () {
                           parent.layer.closeAll();
                        }
                        ,end:function() {
                               location.reload();
                            }
                    });
                    break;
            };
        });









    });


    function doSearch() {
        //通过jquery获取参数的值
        var name=$("#name").val();
        var providername=$("#providername").val();
        var ispay=$("#ispay").val();

        table.reload('orderTable', {
            where: {
                name:name,
                providername:providername,
                ispay:ispay
            },page: {
                curr:1
            }
        });

    }


  layui.config({
        base: '/static/dist/'
    }).extend({
        notice: 'notice'
    });



  //镜像表格样式







</script>



</body>
</html>